package com.beyond.pm.ui.home.feature

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MenuOpen
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.beyond.pm.adapter.LazyGridAdapter
import com.beyond.pm.bean.RouteScreenParameter
import com.beyond.pm.component.MyIconButton
import com.beyond.pm.component.MyLazyVerticalGrid
import com.beyond.pm.component.MyTopBar
import com.beyond.pm.component.MyTopBarStyle
import com.beyond.pm.component.proxy.FeatureProxy
import com.beyond.pm.local.LocalNavController
import com.beyond.pm.local.AppNavHostController

/**
 * @author chen
 * @time 2023/5/31 13:34
 * @name ProjectManage
 * @class describe
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FeatureScreen(enter: Boolean, openDrawer: () -> Unit) {
    val nav = LocalNavController.current
    val appNav = remember(nav) { AppNavHostController(nav) }
    Scaffold(
        topBar = {
            MyTopBar(
                style = MyTopBarStyle.CenterAligned,
                navigationIcon = {
                    MyIconButton(
                        imageVector = Icons.Default.MenuOpen,
                        onClick = openDrawer
                    )
                },
                title = {
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.Center,
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Icon(
                            imageVector = RouteScreenParameter.Feature.bean.icon,
                            contentDescription = null,
                        )
                        Spacer(modifier = Modifier.width(10.dp))
                        Text(text = stringResource(id = RouteScreenParameter.Feature.bean.labelId))
                    }
                },
            )
        },
    ) {
        if (enter)
            FeatureContent(it, appNav)
    }
}

private val features = listOf(
    RouteScreenParameter.Product.bean,
    RouteScreenParameter.Activity.bean,
    RouteScreenParameter.Video.bean,
    RouteScreenParameter.Point.bean,
    RouteScreenParameter.Order.bean,
    RouteScreenParameter.Gold.bean,
    RouteScreenParameter.Gold.bean
)
@Composable
private fun FeatureContent(paddingValues: PaddingValues, appNav: AppNavHostController) {
    val adapter = remember {
        LazyGridAdapter(
            mutableListOf(
                FeatureProxy(onClickListener = { data ->
                    appNav.navigate(data.routerStr)
                    Log.e("======>", "1222222222 ${data.routerStr}")
                })
            )
        )
    }
    MyLazyVerticalGrid(
        modifier = Modifier.fillMaxSize(),
        dataList = features,
        adapter = adapter,
        contentPadding = paddingValues
    )
}
